package com.hansheng.dao.impl;

import com.hansheng.dao.SheetDao;
import com.hansheng.entity.*;

import java.util.List;

/**
 * Created by GoldenMan on 2017/5/12.
 */
public class SheetDaoImpl implements SheetDao {
    private BaseDao baseDao;

    public boolean saveSheet(SheetEntity sheetEntity) {
        return baseDao.saveEntity(sheetEntity);
    }

    @Override
    public boolean saveOutForm(OutFormEntity outFormEntity) {
        return baseDao.saveEntity(outFormEntity);
    }

    @Override
    public boolean saveOutDetail(OutDetailEntity outDetailEntity) {
        return baseDao.saveEntity(outDetailEntity);
    }

    @Override
    public boolean saveTailing(TailingEntity tailingEntity) {
        return baseDao.saveEntity(tailingEntity);
    }

    @Override
    public boolean saveTailingDetail(TailingDetailEntity tailingDetailEntity) {
        return baseDao.saveEntity(tailingDetailEntity);
    }

    @Override
    public boolean changeOldSheetStatus(int outId) {
        int flag=0;
        try {
            String hql ="update SheetEntity s Set s.status=? where s.sid IN(SELECT sid FROM OutDetailEntity WHERE outId=8)";
//            Object[] params = {1, outId};
            Object[] params = {1};
           flag=baseDao.updateByQuery(hql, params);
        }catch (Exception e){
            e.printStackTrace();
        }
//        String hql = "update SheetEntity s,OutDetailEntity od set s.status=? where s.sid=od.sid and od.outId=?";
        return flag > 0 ? true : false;
    }


    @Override
    public List getSheetListByCondition(String whereHql, Object[] params, int firstResult, int maxResult) {
        return baseDao.getEntityListByConditionWithPage(VSheetEntity.class, whereHql, params, firstResult, maxResult);
    }

    @Override
    public List getAllOutForm() {
        return baseDao.getEntityList(OutFormEntity.class);
    }

    @Override
    public List<OutFormEntity> getOutFormByQuery(String hql, Object[] params) {
        return baseDao.getEntityListByQuery(hql, params);
    }

    @Override
    public List<OutFormEntity> getOutFormListByCondition(String whereHql, Object[] params) {
        return baseDao.getEntityListByCondition(OutFormEntity.class, whereHql, params);
    }

    public boolean chooseSheet() {
        return false;
    }

    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }
}
